package com.qs.sckill.result;

/**
 * 对返回结果封装
 *
 * @param <T> 返回结果中data的类型
 * @author qinyupeng
 * @since 2019-07-18 15:56:21
 */
public class Result<T> {

    private int code;

    private String msg;

    private T data;

    private Result(T data) {
        this(CodeMsg.SUCCESS);
        this.data = data;
    }


    private Result(CodeMsg codeMsg) {
        if (codeMsg == null) {
            return;
        }

        this.code = codeMsg.getCode();
        this.msg = codeMsg.getMsg();
    }


    /**
     * 成功的时候回调
     */
    public static <T> Result<T> success(T data) {
        return new Result<>(data);
    }

    /**
     * 失败的时候回调
     */
    public static <T> Result<T> error(CodeMsg codeMsg) {
        return new Result<>(codeMsg);
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public T getData() {
        return data;
    }
}
